<template>
  <div class="views-container">
    <div class="crud-group">
      <el-input
        v-model="paramsForm.serviceType"
        placeholder="请输入组件"
        clearable
      />
      <el-input
        v-model="paramsForm.targetName"
        placeholder="请输入指标"
        clearable
      />
      <el-input
        v-model="paramsForm.state"
        placeholder="请输入发送状态"
        clearable
      />
      <div>
        <el-button
          icon="el-icon-search"
          type="success"
          @click="getData"
        >搜索</el-button>
      </div>
    </div>
    <el-table
      ref="table"
      v-loading="isLoading"
      :data="data"
      style="margin-top:10px"
    >
      <el-table-column
        type="index"
        label="序号"
        width="55"
      />
      <el-table-column
        label="集群"
        prop="cmName"
      />
      <el-table-column
        label="子集群"
        prop="clusterName"
      />
      <el-table-column
        label="组件"
        prop="serviceType"
      />
      <el-table-column
        label="指标"
        prop="targetName"
      />
      <el-table-column
        label="接收人"
        prop="recipientUser"
      />
      <el-table-column
        label="告警内容"
        prop="warnContent"
        show-overflow-tooltip
      />
      <el-table-column
        label="发送类型"
        prop="sendingType"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.sendingType=='1'">微信</span>
          <span v-if="scope.row.sendingType=='2'">钉钉</span>
          <span v-if="scope.row.sendingType=='3'">微信,钉钉</span>
        </template>
      </el-table-column>
      <el-table-column
        label="发送状态"
        prop="state"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.state=='1'">成功</span>
          <span v-if="scope.row.state=='2'">失败</span>
        </template>
      </el-table-column>
      <el-table-column
        label="发送时间"
        prop="createTime"
      />
    </el-table>
    <div class="pagination-container">
      <el-pagination
        :current-page="paramsForm.current"
        :page-size="paramsForm.size"
        :page-sizes="[5, 10, 20, 30, 40]"
        layout="prev, pager, next,sizes,total"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import parameter from '@/api/phaseTwo/parameter.js'

export default {
  data() {
    return {
      total: 0,
      paramsForm: {
        current: 1,
        size: 10,
        serviceType: '',
        targetName: '',
        state: ''
      },
      data: [],
      isLoading: false,
      permission: {
        add: ['add'],
        edit: ['edit'],
        del: ['del']
      },
      queryOptions: [
        {
          columnName: 'serviceType',
          columnValue: '组件',
          inputType: 1
        },
        {
          columnName: 'targetName',
          columnValue: '指标',
          inputType: 1
        },
        {
          columnName: 'state',
          columnValue: '发送状态',
          selectionData: [
            {
              key: '1',
              label: '成功',
              value: '1'
            },
            {
              key: '2',
              label: '失败',
              value: '2'
            }
          ],
          inputType: 2
        }
      ]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData(resetPage = true) {
      if (resetPage) {
        this.paramsForm.current = 1
      }
      this.isLoading = true
      parameter.getWarnSendLog(this.paramsForm).then((res) => {
        this.data = res.content
        this.total = res.totalElements
      }).finally(() => {
        this.isLoading = false
      })
    },
    handleSizeChange(val) {
      this.paramsForm.size = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.paramsForm.current = val
      this.getData(false)
    }
  }
}
</script>
